<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Callback (computer programming)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Callback_(computer_programming)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Callback_computer_programming rootpage-Callback_computer_programming skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Callback (computer programming)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">For a discussion of callback with computer <a href="Modem" title="Modem">modems</a>, see <a href="Callback_(telecommunications)" title="Callback (telecommunications)">Callback (telecommunications)</a>.</div>
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style>
<p>In <a href="Computer_programming" title="Computer programming">computer programming</a>, a <b>callback</b> is a <a href="Function_(computer_programming)" title="Function (computer programming)">function</a> that is stored as data (a <a href="Reference_(computer_science)" title="Reference (computer science)">reference</a>) and designed to be called by another function – often <i>back</i> to the original <a href="Abstraction_(computer_science)" title="Abstraction (computer science)">abstraction layer</a>.A function that accepts a callback <a href="Parameter_(computer_programming)" title="Parameter (computer programming)">parameter</a> may be designed to call back before <a href="Return_statement" title="Return statement">returning</a> to its caller which is known as <i><a href="Synchronization_(computer_science)" title="Synchronization (computer science)">synchronous</a></i> or <i>blocking</i>.The function that accepts a callback may be designed to store the callback so that it can be called back after returning which is known as <i>asynchronous</i>, <i><a href="Non-blocking_algorithm" title="Non-blocking algorithm">non-blocking</a></i> or <i>deferred</i>.
</p><p><a href="Programming_languages" class="mw-redirect" title="Programming languages">Programming languages</a> support callbacks in different ways such as <a href="Function_pointers" class="mw-redirect" title="Function pointers">function pointers</a>, <a href="Lambda_(programming)" class="mw-redirect" title="Lambda (programming)">lambda expressions</a> and <a href="Block_(programming)" title="Block (programming)">blocks</a>.A callback can be likened to leaving instructions with a tailor for what to do when a suit is ready, such as calling a specific phone number or delivering it to a given address.These instructions represent a callback: a function provided in advance to be executed later, often by a different part of the system and not necessarily by the one that received it.The term <i>callback</i> can be misleading, as it does not necessarily imply a return to the original caller, unlike a <a href="Callback_(telecommunications)" title="Callback (telecommunications)">telephone callback</a>.Mesa programming language formalised the callback mechanism used in Programming Languages. By passing a procedure as a parameter, Mesa essentially delegated the execution of that procedure to a later point in time when a specific event occurred, similar to how callbacks are implemented in modern programming languages.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Use">Use</h2></div>
<p>A blocking callback runs in the <a href="Execution_(computing)" title="Execution (computing)">execution</a> context of the function that passes the callback. A deferred callback can run in a different context such as during <a href="Interrupt" title="Interrupt">interrupt</a> or from a <a href="Thread_(computing)" title="Thread (computing)">thread</a>. As such, a deferred callback can be used for synchronization and delegating work to another thread.
</p>
<div class="mw-heading mw-heading3"><h3 id="Event_handling">Event handling</h3></div>
<p>A callback can be used for event handling. Often, consuming code registers a callback for a particular type of event. When that event occurs, the callback is called.Callbacks are often used to program the <a href="Graphical_user_interface" title="Graphical user interface">graphical user interface</a> (GUI) of a program that runs in a <a href="Windowing_system" title="Windowing system">windowing system</a>. The application supplies a reference to a custom callback function for the windowing system to call. The windowing system calls this function to notify the application of events like <a href="Computer_mouse" title="Computer mouse">mouse</a> clicks and <a href="Computer_keyboard" title="Computer keyboard">key</a> presses.
</p>
<div class="mw-heading mw-heading3"><h3 id="Asynchronous_action">Asynchronous action</h3></div>
<p>A callback can be used to implement asynchronous processing.
</p><p>A caller requests an action and provides a callback to be called when the action completes which might be long after the request is made.
</p>
<div class="mw-heading mw-heading3"><h3 id="Polymorphism">Polymorphism</h3></div>
<p>A callback can be used to implement <a href="Polymorphism_(computer_science)" title="Polymorphism (computer science)">polymorphism</a>. In the following pseudocode, <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">say_hi</code> can take either <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">write_status</code> or <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">write_error</code>.
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span class="k">def</span><span class="w"> </span><span class="nf">write_status</span><span class="p">(</span><span class="n">message</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">write</span><span class="p">(</span><span class="n">stdout</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">write_error</span><span class="p">(</span><span class="n">message</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">write</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">say_hi</span><span class="p">(</span><span class="n">write</span><span class="p">):</span>
<span class="n">write</span><span class="p">(</span><span class="s2">"Hello world"</span><span class="p">)</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Implementation">Implementation</h2></div>
<p>The callback technology is implemented differently by <a href="Programming_language" title="Programming language">programming language</a>.
</p><p>In <a href="Assembly_language" title="Assembly language">assembly</a>, <a href="C_(programming_language)" title="C (programming language)">C</a>, <a href="C%2B%2B" title="C++">C++</a>, <a href="Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a>, <a href="Modula2" class="mw-redirect" title="Modula2">Modula2</a> and other languages, a callback function is stored internally as a <a href="Function_pointer" title="Function pointer">function pointer</a>. Using the same storage allows different languages to directly share callbacks without a <a href="Program_lifecycle_phase" title="Program lifecycle phase">design-time or runtime</a> <a href="Interoperability" title="Interoperability">interoperability</a> <a href="Abstraction_layer" title="Abstraction layer">layer</a>. For example, the <a href="Windows_API" title="Windows API">Windows API</a> is accessible via multiple languages, compilers and assemblers.C++ also allows objects to provide an implementation of the function call operation. The <a href="Standard_Template_Library" title="Standard Template Library">Standard Template Library</a> accepts these objects (called <i><a href="Function_object" title="Function object">functors</a></i>) as parameters.Many <a href="Dynamic_programming_language" title="Dynamic programming language">dynamic languages</a>, such as <a href="JavaScript" title="JavaScript">JavaScript</a>, <a href="Lua_(programming_language)" class="mw-redirect" title="Lua (programming language)">Lua</a>, <a href="Python_(programming_language)" title="Python (programming language)">Python</a>, <a href="Perl" title="Perl">Perl</a><sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> and <a href="PHP" title="PHP">PHP</a>, allow a function object to be passed.<a href="List_of_CLI_languages" title="List of CLI languages">CLI languages</a> such as <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a> and <a href="VB.NET" class="mw-redirect" title="VB.NET">VB.NET</a> provide a <a href="Type_safety" title="Type safety">type-safe</a> encapsulating function reference known as <a href="Delegate_(CLI)" title="Delegate (CLI)">delegate</a>.Events and <a href="Event_handlers" class="mw-redirect" title="Event handlers">event handlers</a>, as used in .NET languages, provide for callbacks.Functional languages generally support <a href="First-class_functions" class="mw-redirect" title="First-class functions">first-class functions</a>, which can be passed as callbacks to other functions, stored as data or returned from functions.
</p><p>Many languages, including Perl, Python, <a href="Ruby_(programming_language)" title="Ruby (programming language)">Ruby</a>, <a href="Smalltalk" title="Smalltalk">Smalltalk</a>, <a href="C%2B%2B" title="C++">C++</a> (11+), C# and VB.NET (new versions) and most functional languages, support <a href="Lambda_(programming)" class="mw-redirect" title="Lambda (programming)">lambda expressions</a>, unnamed functions with inline syntax, that generally acts as callbacks..In some languages, including <a href="Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a>, <a href="ML_(programming_language)" title="ML (programming language)">ML</a>, JavaScript, Perl, Python, Smalltalk, PHP (since 5.3.0),<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> C++ (11+), Java (since 8),<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup> and many others, a lambda can be a <a href="Closure_(computer_science)" class="mw-redirect" title="Closure (computer science)">closure</a>, i.e. can access variables locally defined in the context in which the lambda is defined.In an <a href="Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a> language such as <a href="Java_(programming_language)" title="Java (programming language)">Java</a> versions before function-valued arguments, the behavior of a callback can be achieved by passing an object that implements an interface. The methods of this object are callbacks.In <a href="PL/I" title="PL/I">PL/I</a> and <a href="ALGOL_60" title="ALGOL 60">ALGOL 60</a> a callback procedure may need to be able to access local variables in containing blocks, so it is called through an <i>entry variable</i> containing both the entry point and context information. <sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Example_code">Example code</h2></div>
<div class="mw-heading mw-heading3"><h3 id="C">C</h3></div>
<p>Callbacks have a wide variety of uses, for example in error signaling: a <a href="Unix" title="Unix">Unix</a> program might not want to terminate immediately when it receives <a href="SIGTERM" class="mw-redirect" title="SIGTERM">SIGTERM</a>, so to make sure that its termination is handled properly, it would register the cleanup function as a callback. Callbacks may also be used to control whether a function acts or not: <a href="Xlib" title="Xlib">Xlib</a> allows custom predicates to be specified to determine whether a program wishes to handle an event.In the following <a href="C_(programming_language)" title="C (programming language)">C</a> code, function <code>print_number</code> uses parameter <code>get_number</code> as a blocking callback. <code>print_number</code> is called with <code>get_answer_to_most_important_question</code> which acts as a callback function. When run the output is: "Value: 42".
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="cp">#include</span><span class="w"> </span><span class="cpf"><stdio.h></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><stdlib.h></span>
<span class="kt">void</span><span class="w"> </span><span class="nf">print_number</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">get_number</span><span class="p">)(</span><span class="kt">void</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">get_number</span><span class="p">();</span>
<span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"Value: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span><span class="w"> </span><span class="nf">get_answer_to_most_important_question</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">42</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">print_number</span><span class="p">(</span><span class="n">get_answer_to_most_important_question</span><span class="p">);</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="C++">C++</h3></div>
<p>In C++, <a href="Function_object" title="Function object">functor</a> can be used in addition to function pointer.
</p>
<div class="mw-heading mw-heading3"><h3 id="C#">C#</h3></div>
<p>In the following <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a> code,
method <code>Helper.Method</code> uses parameter <code>callback</code> as a blocking callback. <code>Helper.Method</code> is called with <code>Log</code> which acts as a callback function. When run, the following is written to the console: "Callback was: Hello world".
</p>
<div class="mw-highlight mw-highlight-lang-c# mw-content-ltr" dir="ltr"><pre><span class="k">public</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">MainClass</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="k">void</span><span class="w"> </span><span class="nf">Main</span><span class="p">(</span><span class="kt">string</span><span class="p">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Helper</span><span class="w"> </span><span class="n">helper</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Helper</span><span class="p">();</span>
<span class="w"> </span><span class="n">helper</span><span class="p">.</span><span class="n">Method</span><span class="p">(</span><span class="n">Log</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="k">void</span><span class="w"> </span><span class="nf">Log</span><span class="p">(</span><span class="kt">string</span><span class="w"> </span><span class="n">str</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">$"Callback was: {str}"</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
<span class="k">public</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">Helper</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="k">void</span><span class="w"> </span><span class="nf">Method</span><span class="p">(</span><span class="n">Action</span><span class="o"><</span><span class="kt">string</span><span class="o">></span><span class="w"> </span><span class="n">callback</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">callback</span><span class="p">(</span><span class="s">"Hello world"</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Kotlin">Kotlin</h3></div>
<p>In the following <a href="Kotlin_(programming_language)" title="Kotlin (programming language)">Kotlin</a> code, function <code>askAndAnswer</code> uses parameter <code>getAnswer</code> as a blocking callback. <code>askAndAnswer</code> is called with <code>getAnswerToMostImportantQuestion</code> which acts as a callback function. Running this will tell the user that the answer to their question is "42".
</p>
<div class="mw-highlight mw-highlight-lang-kotlin mw-content-ltr" dir="ltr"><pre><span class="kd">fun</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">print</span><span class="p">(</span><span class="s">"Enter the most important question: "</span><span class="p">)</span>
<span class="w"> </span><span class="kd">val</span><span class="w"> </span><span class="nv">question</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">readLine</span><span class="p">()</span>
<span class="w"> </span><span class="n">askAndAnswer</span><span class="p">(</span><span class="n">question</span><span class="p">,</span><span class="w"> </span><span class="o">::</span><span class="n">getAnswerToMostImportantQuestion</span><span class="p">)</span>
<span class="p">}</span>
<span class="kd">fun</span><span class="w"> </span><span class="nf">getAnswerToMostImportantQuestion</span><span class="p">():</span><span class="w"> </span><span class="kt">Int</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="m">42</span>
<span class="p">}</span>
<span class="kd">fun</span><span class="w"> </span><span class="nf">askAndAnswer</span><span class="p">(</span><span class="n">question</span><span class="p">:</span><span class="w"> </span><span class="kt">String?</span><span class="p">,</span><span class="w"> </span><span class="n">getAnswer</span><span class="p">:</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="kt">Int</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="s">"Question: </span><span class="si">$</span><span class="n">question</span><span class="s">"</span><span class="p">)</span>
<span class="w"> </span><span class="n">println</span><span class="p">(</span><span class="s">"Answer: </span><span class="si">${</span><span class="n">getAnswer</span><span class="p">()</span><span class="si">}</span><span class="s">"</span><span class="p">)</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="JavaScript">JavaScript</h3></div>
<p>In the following <a href="JavaScript" title="JavaScript">JavaScript</a> code, function <code>calculate</code> uses parameter <code>operate</code> as a blocking callback. <code>calculate</code> is called with <code>multiply</code> and then with <code>sum</code> which act as callback functions.
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span class="kd">function</span><span class="w"> </span><span class="nx">calculate</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="w"> </span><span class="nx">b</span><span class="p">,</span><span class="w"> </span><span class="nx">operate</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">operate</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="w"> </span><span class="nx">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">function</span><span class="w"> </span><span class="nx">multiply</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="w"> </span><span class="nx">b</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">a</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nx">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">function</span><span class="w"> </span><span class="nx">sum</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="w"> </span><span class="nx">b</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">a</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nx">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// outputs 20</span>
<span class="nx">alert</span><span class="p">(</span><span class="nx">calculate</span><span class="p">(</span><span class="mf">10</span><span class="p">,</span><span class="w"> </span><span class="mf">2</span><span class="p">,</span><span class="w"> </span><span class="nx">multiply</span><span class="p">));</span>
<span class="c1">// outputs 12</span>
<span class="nx">alert</span><span class="p">(</span><span class="nx">calculate</span><span class="p">(</span><span class="mf">10</span><span class="p">,</span><span class="w"> </span><span class="mf">2</span><span class="p">,</span><span class="w"> </span><span class="nx">sum</span><span class="p">));</span>
</pre></div>
<p>The collection method <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">.each()</code> of the <a href="JQuery" title="JQuery">jQuery</a> <a href="JavaScript_libraries" class="mw-redirect" title="JavaScript libraries">library</a> uses the function passed to it as a blocking callback. It calls the callback for each item of the collection. For example:
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span class="nx">$</span><span class="p">(</span><span class="s2">"li"</span><span class="p">).</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">index</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">index</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s2">": "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">text</span><span class="p">());</span>
<span class="p">});</span>
</pre></div>
<p>Deferred callbacks are commonly used for handling events from the user, the client and timers. Examples can be found in <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">addEventListener</code>, <a href="Ajax_(programming)" title="Ajax (programming)">Ajax</a> and <code><a href="XMLHttpRequest" title="XMLHttpRequest">XMLHttpRequest</a></code>.
<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>
</p><p>In addition to using callbacks in JavaScript source code, C functions that take a function are supported via js-ctypes.<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Red_and_REBOL">Red and REBOL</h3></div>
<p>The following <a href="REBOL" class="mw-redirect" title="REBOL">REBOL</a>/<a href="Red_(programming_language)" title="Red (programming language)">Red</a> code demonstrates callback use.
</p>
<ul><li>As alert requires a string, form produces a string from the result of calculate</li>
<li>The get-word! values (i.e., :calc-product and :calc-sum) trigger the interpreter to return the code of the function rather than evaluate with the function.</li>
<li>The datatype! references in a block! [float! integer!] restrict the type of values passed as arguments.</li></ul>
<div class="mw-highlight mw-highlight-lang-red mw-content-ltr" dir="ltr"><pre><span class="nv">Red</span> <span class="gs">[</span><span class="gu">Title:</span> <span class="s">"Callback example"</span><span class="gs">]</span>
<span class="gu">calculate:</span> <span class="nb">func</span> <span class="gs">[</span>
<span class="nv">num1</span> <span class="gs">[</span><span class="kt">number!</span><span class="gs">]</span>
<span class="nv">num2</span> <span class="gs">[</span><span class="kt">number!</span><span class="gs">]</span>
<span class="nv">callback-function</span> <span class="gs">[</span><span class="kt">function!</span><span class="gs">]</span>
<span class="gs">][</span>
<span class="nv">callback-function</span> <span class="nv">num1</span> <span class="nv">num2</span>
<span class="gs">]</span>
<span class="gu">calc-product:</span> <span class="nb">func</span> <span class="gs">[</span>
<span class="nv">num1</span> <span class="gs">[</span><span class="kt">number!</span><span class="gs">]</span>
<span class="nv">num2</span> <span class="gs">[</span><span class="kt">number!</span><span class="gs">]</span>
<span class="gs">][</span>
<span class="nv">num1</span> <span class="o">*</span> <span class="nv">num2</span>
<span class="gs">]</span>
<span class="gu">calc-sum:</span> <span class="nb">func</span> <span class="gs">[</span>
<span class="nv">num1</span> <span class="gs">[</span><span class="kt">number!</span><span class="gs">]</span>
<span class="nv">num2</span> <span class="gs">[</span><span class="kt">number!</span><span class="gs">]</span>
<span class="gs">][</span>
<span class="nv">num1</span> <span class="o">+</span> <span class="nv">num2</span>
<span class="gs">]</span>
<span class="c">; alerts 75, the product of 5 and 15</span>
<span class="nv">alert</span> <span class="nf">form</span> <span class="nv">calculate</span> <span class="m">5</span> <span class="m">15</span> <span class="gu">:calc-product</span>
<span class="c">; alerts 20, the sum of 5 and 15</span>
<span class="nv">alert</span> <span class="nf">form</span> <span class="nv">calculate</span> <span class="m">5</span> <span class="m">15</span> <span class="gu">:calc-sum</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Rust">Rust</h3></div>
<p><a href="Rust_(programming_language)" title="Rust (programming language)">Rust</a> have the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">Fn</code>, <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">FnMut</code> and <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">FnOnce</code> traits.<sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-rust mw-content-ltr" dir="ltr"><pre><span class="k">fn</span><span class="w"> </span><span class="nf">call_with_one</span><span class="o"><</span><span class="n">F</span><span class="o">></span><span class="p">(</span><span class="n">func</span><span class="p">:</span><span class="w"> </span><span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">-></span><span class="w"> </span><span class="kt">usize</span>
<span class="w"> </span><span class="nc">where</span><span class="w"> </span><span class="n">F</span><span class="p">:</span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="kt">usize</span><span class="p">)</span><span class="w"> </span><span class="p">-></span><span class="w"> </span><span class="kt">usize</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">func</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="p">}</span>
<span class="kd">let</span><span class="w"> </span><span class="n">double</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span>
<span class="fm">assert_eq!</span><span class="p">(</span><span class="n">call_with_one</span><span class="p">(</span><span class="n">double</span><span class="p">),</span><span class="w"> </span><span class="mi">2</span><span class="p">);</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Lua">Lua</h3></div>
<p>In this <a href="Lua" title="Lua">Lua</a> code, function <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">calculate</code> accepts the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">operation</code> parameter which is used as a blocking callback. <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">calculate</code> is called with both <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">add</code> and <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">multiply</code>, and then uses an <a href="Anonymous_function" title="Anonymous function">anonymous function</a> to divide.
</p>
<div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span class="kr">function</span><span class="w"> </span><span class="nf">calculate</span><span class="p">(</span><span class="nv">a</span><span class="p">,</span><span class="w"> </span><span class="nv">b</span><span class="p">,</span><span class="w"> </span><span class="nv">operation</span><span class="p">)</span>
<span class="w"> </span><span class="kr">return</span><span class="w"> </span><span class="nf">operation</span><span class="p">(</span><span class="nv">a</span><span class="p">,</span><span class="w"> </span><span class="nv">b</span><span class="p">)</span>
<span class="kr">end</span>
<span class="kr">function</span><span class="w"> </span><span class="nf">multiply</span><span class="p">(</span><span class="nv">a</span><span class="p">,</span><span class="w"> </span><span class="nv">b</span><span class="p">)</span>
<span class="w"> </span><span class="kr">return</span><span class="w"> </span><span class="nv">a</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="nv">b</span>
<span class="kr">end</span>
<span class="kr">function</span><span class="w"> </span><span class="nf">add</span><span class="p">(</span><span class="nv">a</span><span class="p">,</span><span class="w"> </span><span class="nv">b</span><span class="p">)</span>
<span class="w"> </span><span class="kr">return</span><span class="w"> </span><span class="nv">a</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nv">b</span>
<span class="kr">end</span>
<span class="nb">print</span><span class="p">(</span><span class="nf">calculate</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="p">,</span><span class="w"> </span><span class="nv">multiply</span><span class="p">))</span><span class="w"> </span><span class="c1">-- outputs 200</span>
<span class="nb">print</span><span class="p">(</span><span class="nf">calculate</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="p">,</span><span class="w"> </span><span class="nv">add</span><span class="p">))</span><span class="w"> </span><span class="c1">-- outputs 30</span>
<span class="c1">-- an example of a callback using an anonymous function</span>
<span class="nb">print</span><span class="p">(</span><span class="nf">calculate</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="p">,</span><span class="w"> </span><span class="kr">function</span><span class="p">(</span><span class="nv">a</span><span class="p">,</span><span class="w"> </span><span class="nv">b</span><span class="p">)</span>
<span class="w"> </span><span class="kr">return</span><span class="w"> </span><span class="nv">a</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="nv">b</span><span class="w"> </span><span class="c1">-- outputs 0.5</span>
<span class="kr">end</span><span class="p">))</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Python">Python</h3></div>
<p>In the following <a href="Python_(programming_language)" title="Python (programming language)">Python</a> code, function <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">calculate</code> accepts a parameter <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">operate</code> that is used as a blocking callback. <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">calculate</code> is called with <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">square</code> which acts as a callback function.
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span class="k">def</span><span class="w"> </span><span class="nf">square</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
<span class="k">return</span> <span class="n">val</span> <span class="o">**</span> <span class="mi">2</span>
<span class="k">def</span><span class="w"> </span><span class="nf">calculate</span><span class="p">(</span><span class="n">operate</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
<span class="k">return</span> <span class="n">operate</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
<span class="n">calculate</span><span class="p">(</span><span class="n">square</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="c1"># outputs: 25</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Julia">Julia</h3></div>
<p>In the following <a href="Julia_(programming_language)" title="Julia (programming language)">Julia</a> code, function <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">calculate</code> accepts a parameter <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">operate</code> that is used as a blocking callback. <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">calculate</code> is called with <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">square</code> which acts as a callback function.
</p>
<div class="mw-highlight mw-highlight-lang-jlcon mw-content-ltr" dir="ltr"><pre><span class="gp">julia></span><span class="w"> </span><span class="n">square</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">val</span><span class="o">^</span><span class="mi">2</span>
<span class="go">square (generic function with 1 method)</span>
<span class="gp">julia></span><span class="w"> </span><span class="n">calculate</span><span class="p">(</span><span class="n">operate</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">operate</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
<span class="go">calculate (generic function with 1 method)</span>
<span class="gp">julia></span><span class="w"> </span><span class="n">calculate</span><span class="p">(</span><span class="n">square</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">)</span>
<span class="go">25</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1266661725">
/* start https://en.wikipedia.org/ */
.mw-parser-output .portalbox{padding:0;margin:0.5em 0;display:table;box-sizing:border-box;max-width:175px;list-style:none}.mw-parser-output .portalborder{border:1px solid var(--border-color-base,#a2a9b1);padding:0.1em;background:var(--background-color-neutral-subtle,#f8f9fa)}.mw-parser-output .portalbox-entry{display:table-row;font-size:85%;line-height:110%;height:1.9em;font-style:italic;font-weight:bold}.mw-parser-output .portalbox-image{display:table-cell;padding:0.2em;vertical-align:middle;text-align:center}.mw-parser-output .portalbox-link{display:table-cell;padding:0.2em 0.2em 0.2em 0.3em;vertical-align:middle}@media(min-width:720px){.mw-parser-output .portalleft{margin:0.5em 1em 0.5em 0}.mw-parser-output .portalright{clear:right;float:right;margin:0.5em 0 0.5em 1em}}
/* end https://en.wikipedia.org/ */
</style>
<style data-mw-deduplicate="TemplateStyles:r1184024115">
/* start https://en.wikipedia.org/ */
.mw-parser-output .div-col{margin-top:0.3em;column-width:30em}.mw-parser-output .div-col-small{font-size:90%}.mw-parser-output .div-col-rules{column-rule:1px solid #aaa}.mw-parser-output .div-col dl,.mw-parser-output .div-col ol,.mw-parser-output .div-col ul{margin-top:0}.mw-parser-output .div-col li,.mw-parser-output .div-col dd{page-break-inside:avoid;break-inside:avoid-column}
/* end https://en.wikipedia.org/ */
</style><div class="div-col" style="column-width: 25em;">
<ul><li><a href="Command_pattern" title="Command pattern">Command pattern</a></li>
<li><a href="Continuation-passing_style" title="Continuation-passing style">Continuation-passing style</a></li>
<li><a href="Event_loop" title="Event loop">Event loop</a></li>
<li><a href="Event-driven_programming" title="Event-driven programming">Event-driven programming</a></li>
<li><a href="Implicit_invocation" title="Implicit invocation">Implicit invocation</a></li>
<li><a href="Inversion_of_control" title="Inversion of control">Inversion of control</a></li>
<li><a href="Libsigc%2B%2B" title="Libsigc++">libsigc++</a>, a callback library for C++</li>
<li><a href="Signals_and_slots" title="Signals and slots">Signals and slots</a></li>
<li><a href="User_exit" title="User exit">User exit</a></li></ul>
</div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFE._Sweet1985" class="citation journal cs1">E. Sweet, Richard (1985). <span class="id-lock-subscription" title="Paid subscription required"><a rel="nofollow" class="external text" href="https://dl.acm.org/doi/pdf/10.1145/17919.806843">"The Mesa Programming Environment"</a></span>. <i>ACM SIGPLAN Notices</i>. <b>20</b> (7): <span class="nowrap">216–</span>229. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F17919.806843">10.1145/17919.806843</a>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.unix.org.ua/orelly/perl/cookbook/ch11_05.htm">"Perl Cookbook - 11.4. Taking References to Functions"</a>. 2 July 1999<span class="reference-accessdate">. Retrieved <span class="nowrap">2008-03-03</span></span>.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.unix.org.ua/orelly/perl/advprog/ch04_02.htm">"Advanced Perl Programming - 4.2 Using Subroutine References"</a>. 2 July 1999<span class="reference-accessdate">. Retrieved <span class="nowrap">2008-03-03</span></span>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://secure.php.net/manual/en/functions.anonymous.php">"PHP Language Reference - Anonymous functions"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2011-06-08</span></span>.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html">"What's New in JDK 8"</a>. <i>oracle.com</i>.</cite></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><cite id="CITEREFBelzerHolzmanKent1979" class="citation book cs1">Belzer, Jack; Holzman, Albert G; Kent, Allen, eds. (1979). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=IFmaqTI9-KsC&pg=PA164"><i>Encyclopedia of Computer Science and Technology: Volume 12</i></a>. Marcel Dekker, inc. p. 164. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-8247-2262-0</bdi><span class="reference-accessdate">. Retrieved <span class="nowrap">January 28,</span> 2024</span>.</cite></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://udn.realityripple.com/docs/Mozilla/Creating_JavaScript_callbacks_in_components#JavaScript_functions_as_callbacks">"Creating JavaScript callbacks in components"</a>. Archive. <i>UDN Web Docs</i> (Documentation page). sec. JavaScript functions as callbacks. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20211216020616/https://udn.realityripple.com/docs/Mozilla/Creating_JavaScript_callbacks_in_components">Archived</a> from the original on 2021-12-16<span class="reference-accessdate">. Retrieved <span class="nowrap">2021-12-16</span></span>.</cite></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><cite id="CITEREFHolleyShepherd" class="citation web cs1">Holley, Bobby; Shepherd, Eric (eds.). <a rel="nofollow" class="external text" href="https://developer.mozilla.org.cach3.com/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/Declaring_and_Using_Callbacks">"Declaring and Using Callbacks"</a>. Docs. <i><a href="Mozilla_Developer_Network" class="mw-redirect" title="Mozilla Developer Network">Mozilla Developer Network</a></i> (Documentation page). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20190117092921/https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/Declaring_and_Using_Callbacks">Archived</a> from the original on 2019-01-17<span class="reference-accessdate">. Retrieved <span class="nowrap">2021-12-16</span></span>.</cite></span>
</li>
<li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://doc.rust-lang.org/std/ops/trait.Fn.html">"Fn in std::ops - Rust"</a>. <i>doc.rust-lang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">18 January</span> 2025</span>.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="https://learn.microsoft.com/en-us/archive/msdn-magazine/2002/december/using-net-implementing-callback-notifications-using-delegates">Basic Instincts: Implementing Callback Notifications Using Delegates</a> - <a href="MSDN_Magazine" class="mw-redirect" title="MSDN Magazine">MSDN Magazine</a>, December 2002</li>
<li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20080916192721/http://www.javaworld.com/javaworld/javatips/jw-javatip10.html">Implement callback routines in Java</a></li>
<li><a rel="nofollow" class="external text" href="https://www.codeproject.com/Articles/7865/Implement-Script-Callback-Framework-in-ASP-NET-1-x">Implement Script Callback Framework in ASP.NET 1.x</a> - Code Project, 2 August 2004</li>
<li>Interfacing C++ member functions with C libraries (archived from the original on July 6, 2011)</li>
<li><a rel="nofollow" class="external text" href="http://gotw.ca/gotw/083.htm">Style Case Study #2: Generic Callbacks</a></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-08-05" href="https://en.wikipedia.org/wiki/?title=Callback_(computer_programming)&oldid=1304360560">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>